function copySize() {
  if (documents.length > 0) {
    var copyString = "";
    // 获取画板两点坐标
    var artboardX1 = activeDocument.artboards[0].artboardRect[0];
    var artboardY1 = activeDocument.artboards[0].artboardRect[1];
    var artboardX2 = activeDocument.artboards[0].artboardRect[2];
    var artboardY2 = activeDocument.artboards[0].artboardRect[3];
    var artboardWidth = artboardX2 - artboardX1;
    var artboardHeight = artboardY1 - artboardY2;
    copyString = trimEndZero(formatNum(pointToMM(artboardWidth), 1)) + "x" + trimEndZero(formatNum(pointToMM(artboardHeight), 1));
    // 判断是否选中文本
    var elementsSelected = activeDocument.selection;
    if (elementsSelected.length > 0) {
      for (j = 0; j < elementsSelected.length; j++) {
        if (elementsSelected[j].typename == "TextFrame") {
          copyString = copyString + " - " + elementsSelected[j].contents;
        }
        elementsSelected[j].selected = false;
      }
    }
    
    //建立图层
    var ifExist = false;
    for (i = 0; i < activeDocument.layers.length; i++) {
      if (activeDocument.layers[i].name == copyString) {
        ifExist = true;
      }
    }
    if (!ifExist) {
      newLayer = activeDocument.layers.add();
      newLayer.name = copyString;
      newLayer.zOrder(ZOrderMethod.SENDTOBACK);
    }
  } else {
    alert("请先打开一个文档!");
  }
}

function pointToMM(numIn) {
  return (numIn / 72) * 25.4;
}

function formatNum(numIn, accuracyIn) {
  var tempNum = numIn.toFixed(accuracyIn + 2).slice(0, -1);
  var tempNumString = "" + tempNum;
  var lastNum = parseInt(tempNumString.charAt(tempNumString.length - 1));
  if (lastNum != 0) {
    var zeroString = "";
    var tempString = "";
    for (k = 1; k < accuracyIn; k++) {
      zeroString += "0";
    }
    tempString = "0." + zeroString + "1";
    // 此时area为字符串
    numIn = numIn.toFixed(accuracyIn + 1).slice(0, -1);
    numIn = parseFloat(numIn) + parseFloat(tempString);
  } else {
    numIn = numIn.toFixed(accuracyIn + 1).slice(0, -1);
  }
  return numIn;
}

function trimEndZero(numIn) {
  var originString = "" + numIn;
  numIn = parseFloat(originString);
  return numIn;
}
